package com.example.java.serializable;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class SerialObject {


    public static void main(String[] args) {
//        Orientation origin = Orientation.HORIZONTAL;
        try {

            Employee harry = new Employee("Harry Hacker", 50000, 1989, 10, 1);
            Employee carl = new Employee("Carl Cracker", 60000, 2000, 10, 1);
            Employee tony = new Employee("Tony Tester", 80000, 2015, 10, 1);

            ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("Orientation.dat"));
            out.writeObject(harry);
            out.close();
            ObjectInputStream in = new ObjectInputStream(new FileInputStream("Orientation.dat"));
            Employee emp = (Employee)in.readObject();
            System.out.println(emp);
//            ObjectInputStream in = new ObjectInputStream(new FileInputStream("Orientation.dat"));
//            Orientation saved = (Orientation)in.readObject();
//            System.out.println("saved:"+saved);
////           在Orientation对象中添加objectResolve方法后 使得枚举安全类型对象序列化对象唯一
//            if (saved == Orientation.HORIZONTAL) {
//                System.out.println("相等");
//            } else {
////                如果不加objectResolve方法,那么即使是枚举安全类型的对象,序列化,反序列化后的对象不相等.
//                System.out.println("不相等");
//            }
        }catch (Exception e) {
            System.out.println("出錯了");
        }

    }
}
